<template>
    <div class="page">
        <div class="msgTop">
            <div class="userImg floatBox">
                <img src="../../../images/Group 126@2x.png">
            </div>
            <div class="userMsg floatBox">
                <div v-if="!isdenglu && userName" class="pl3">
                    <span class='userPhone'>{{userName}}</span>
                </div>
                <div v-if='!isdenglu && grade' class="userInfo_last">
                    <span class="lh16">{{grade}}:{{totalGrowthValue}}</span>
                </div>
                <span class="fs24 whiteText mt14" v-if="isdenglu">登陆</span>
            </div>
            <div v-if="!isdenglu" class="userSet" @click="toNext('userSetting')">
                <img src="../../../assets/setting.png" alt="">
                <span>设置</span>
            </div>
            <div class="marquee">
                <img src="../../../assets/laba.png" class="laba" alt="">
                <marquee :msgList="lists"></marquee>
            </div>
        </div>
        <div class="top bgcwhite" v-for="(item,index) in listInfo" :key='index' :style="{marginTop:index == 1?0:-3+'rem'}">
            <div @click="clickToPage(list)" v-for="(list,ind) in item" :key="ind" class="line_container" :class="(ind==1)?'relative_r':''">
                <div class="imgbox">
                    <img :src="list.picSrc" v-if='list.picSrc'>
                    <span v-if="list.money" class="fs18 bold">{{list.money}}</span>
                </div>
                <p class="top_childone">{{list.name}}</p>
                <div v-if="ind==0" class="line_abl"></div>
            </div>
        </div>
        
        <!-- 优惠商品列表 -->
        <discount-goods></discount-goods>

        <RegPhone :isShow="isRegPhone" @cancel="cancel" @confirm="confirmCB"></RegPhone>
        <botNavigation />
    </div>
</template>

<script>
import { isRegister, getUserInfo,getUserAmt,queryCouponUsableCount} from "../../../methods/request.js";
import { MessageBox, Toast, InfiniteScroll } from "mint-ui";
import Popup from 'common/popup/popup'
import mixins from 'mixins';
import {listInfo} from './listInfo';
import botNavigation from 'common/botNavigation/index.vue'//底部导航栏组件
import RegPhone from 'common/regPhone/index.vue';//注册手机号组件
export default {
    mixins: [mixins],
    // 最顶部黑色栏
    data() {
        return {
            amt: "",
            isRegPhone: false,
            grade: "",
            phone: "",
            nickName:'sssss',               //用户昵称
            userName:'',                    //用户名称
            list: [],                       //下拉刷新数据列表
            loading: false,                 //控制是否可以下拉刷新
            totalGrowthValue: "--",         //总仙值
            currentPage: 1,                 //当前页
            listInfo:listInfo,              //页面数据
            isdenglu:false, 
            lists:['若在购物期间产生任何问题 请在公众号中留言 我们会尽快处理 若在购物期间产生任何问题 请在公众号中留言 我们会尽快处理 若在购物期间产生任何问题 请在公众号中留言 我们会尽快处理 若在购物期间产生任何问题 请在公众号中留言 我们会尽快处理']                //是否绑定手机号
        };
    },
    created() {
        this.$store.commit("increment", "个人中心");
        document.body.scrollTop = 0
        isRegister({}).then(res => {
            if (res.data.result == "7012") {
                this.isRegPhone = true;                 //是否显示绑定电话号码弹窗
                this.isdenglu = true;
            }else{
                this.getUserInfo();                       //获取等级信息
                this.queryCouponUsableCount();              //获取优惠券数量
            }
        });
    },
    methods: {
        confirmCB(){
            this.isRegPhone = false;
            this.getUserInfo();
        },
        getUserInfo() {
            this.$vux.loading.show({ text: "Loading" });
            getUserInfo({}).then(res => {
                if (res.rspCode == "0000") {
                    this.grade = res.data.grade;
                    this.totalGrowthValue = res.data.totalGrowthValue;
                    this.userName = res.data.name;
                }
                this.$vux.loading.hide();
            }).catch(error => this.$vux.loading.hide());
        },
        clickToPage(val){
            val.toPage && this.toNext(val.toPage,{types: val.types || '00',headName: val.headName});
        },
        //获取优惠券信息
        queryCouponUsableCount(){
            queryCouponUsableCount({}).then(res=>{
                if(res.rspCode == '0000'){
                    this.listInfo[1] && (this.listInfo[1][1]['money'] = res.data.count || '--');
                }
            })
        },
        //取消手机号注册
        cancel(){
            this.isRegPhone = false;
            this.$router.go(-1);
        },
        confirmCB(){
            this.isRegPhone=false;
            this.$store.commit("changeRegState",true);
            this.getUserInfo();                         //获取等级信息
            this.queryCouponUsableCount();              //获取优惠券数量
        }
    },
    components: {
        Popup,
        botNavigation, 
        RegPhone,
    },
};
</script>
<style lang="less" scoped>
@import "~src/components/css/gloState.less";
@import "./index.less";
</style>
